<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="utf-8">
    <title>生鲜商城</title>
    <link href="./themes/ecmoban_dangdang/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
	<h1 id="advertise"></h1>
    <div id="app">
        <div class="top_nav">
            <div class="block">
                <ul class="top_bav_l">
                </ul>
                <div class="header_r">
                    <font id="ECS_MEMBERZONE" v-if="islogin"> 欢迎光临本站！ <s></s>&nbsp; <span> <a style="color: #FF6766;"
                                href="login.html">[用户登录]</a> <a style="color: #FF6766;" href="register.html">[用户注册]</a>
                            <a style="color: #FF6766;" href="slogin.html">[商家登录]</a>
                            <a style="color: #FF6766;" href="sregister.html">[商家注册]</a>
                        </span>
                    </font>
                    <font id="ECS_MEMBERZONE" v-if="!islogin"> 欢迎生鲜推荐系统 <b>{{ realname }}</b> <span><a style="color: #FF6766;"
                                href="cart.html">[购物车]</a><a style="color: #FF6766;" href="usercenter.html">[用户中心]</a>
                            <a style="color: #FF6766;" href="exit.html">[退出系统] </a> </span>
                    </font>
                </div>
            </div>
        </div>
        <div class="clearfix">
            <div class="block header">
                <div class="top">
                    <a href="index.html" class="logo"><img src="themes/ecmoban_dangdang/images/logo.gif" /></a>
                    <div class="head_r">
                        <div class="top_shopCart clearfix"></div>
                    </div>
                </div>
            </div>
        </div>
        <div style="clear: both"></div>
        <div class="menu_box clearfix">
            <div class="block">
                <div class="menu">
                    <a href="index.html" class="cur" rel="nofollow">网站首页</a>
                    <a href="article.html" class="cur" rel="nofollow">生鲜商城公告</a>
                    <span v-if="!islogin">
                        <a href="recommend.html" class="cur" rel="nofollow">推荐商品</a>
                    </span>
                    <a href="all.html" class="cur" rel="nofollow">全部生鲜</a>
                </div>
            </div>
        </div>
        <div class="block box">
            <div class="blank"></div>
            <div id="ur_here">
                当前位置: <a href="index.html">首页</a>
                <code>&gt;</code>
                <a href="all.html">全部生鲜</a>
                <code> &gt; </code>
                <a :href="'cate.html?id='+goods.cateid+''">{{ goods.catename }}</a>
            </div>
        </div>
        <div class="blank"></div>
        <div class="block clearfix">
            <div class="AreaL">
                <div id="category_tree" class="category_tree">
                    <div class="title">所有生鲜分类</div>
                    <dl class="clearfix" style="background: #fafafa; width: 216px; padding: 0;">
                        <div class="box1 cate" id="cate">
                            <h1 style="border-top: none" v-for="item in cateList" :key="item.cateid">
                                <a :href="'cate.html?id='+item.cateid+''" class="  f_l">{{ item.catename }}</a>
                            </h1>
                        </div>
                        <div style="clear: both"></div>
                    </dl>
                </div>
                <div class="blank"></div>
                <div class="box" id='history_div'>
                    <div class="box_1">
                        <h3>
                            <span>猜你喜欢</span>
                        </h3>
                        <div class="boxCenterList clearfix" id='history_list'>
                            <ul class="clearfix" v-for="item in hotList" :key="item.goodsid">
                                <li class="goodsimg">
                                    <a :href="'detail.html?id='+item.goodsid+''" target="_blank"><img
                                            :src="'http://localhost:8080/vue_gxhfztjxt/upfiles/'+item.image" alt=""
                                            class="B_blue" /> </a>
                                </li>
                                <li><a :href="'detail.html?id='+item.goodsid+''" target="_blank"
                                        title="">{{item.goodsname}}</a> <br /> 价格：
                                    <font class="f1">￥{{item.price}}元</font>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="blank5"></div>
            </div>
            <div class="AreaR">
                <div id="goodsInfo" class="clearfix">
                    <div class="imgInfo">
                        <img :src="'http://localhost:8080/vue_gxhfztjxt/upfiles/'+goods.image" alt="" width="360px;"
                            height="360px" />
                        <div class="blank5"></div>
                        <div class="blank"></div>
                    </div>
                    <div class="textInfo">
                        <form action="index/addcart.action" method="post" name="ECS_FORMBUY" id="ECS_FORMBUY">
                            <h1 class="clearfix">{{ goods.goodsname }}</h1>
                            <ul class="ul2 clearfix">
                                <li class="clearfix" style="width: 100%">
                                    <dd>
                                        <strong>价格：</strong>
                                        <font class="shop" id="ECS_SHOPPRICE">￥{{ goods.price }}元</font>
                                    </dd>
                                </li>
                                <li class="clearfix" style="width: 100%">
                                    <dd>
                                        <strong>生鲜类型：</strong><a
                                            :href="'cate.html?id='+goods.cateid+''">{{ goods.catename }}</a>
                                    </dd>
                                </li>
                                <li class="clearfix" style="width: 100%">
                                    <dd>
                                        <strong>加入收藏：</strong><a href="javascript:;" @click="addfav();">加入收藏</a>
                                    </dd>
                                </li>
                                <li class="clearfix" style="width: 100%">
                                    <dd>
                                        <strong>上架日期：</strong>{{ goods.addtime }}
                                    </dd>
                                </li>
                                <li class="clearfix" style="width: 100%">
                                    <dd>
                                        <strong>点击数：</strong>{{ goods.hits }}
                                    </dd>
                                </li>
                                <li class="clearfix" style="width: 100%">
                                    <dd>
                                        <strong>销量：</strong>{{ goods.sellnum }}
                                    </dd>
                                </li>
                                <li class="clearfix" style="width: 100%">
                                    <dd>
                                        <strong>生鲜品牌：</strong>{{ goods.sellername }}
                                    </dd>
                                </li>
                            </ul>
                            <ul class="bnt_ul">
                                <li class="clearfix">
                                    <dd>
                                        <strong>购买数量：</strong> <input name="num" type="text" id="number"
                                            v-model="number" value="1" size="4" style="border: 1px solid #ccc;" />
                                    </dd>
                                </li>
                                <li class="padd">
                                    <a href="javascript:;" @click="addcart()"><img
                                            src="themes/ecmoban_dangdang/images/goumai2.png" /></a>
                                </li>
                            </ul>
                        </form>
                    </div>
                </div>
                <div class="blank"></div>


                <div class="box">

                    <div style="padding: 0 0px;">
                        <div id="com_b" class="history clearfix">
                            <h2>生鲜描述</h2>
                        </div>
                    </div>
                    <div class="box_1">
                        <div id="com_v" class="  " style="padding: 6px;"></div>
                        <div id="com_h">
                            <blockquote>{{ goods.contents }}</blockquote>
                        </div>
                    </div>
                    <div class="blank"></div>
                    <div id="ECS_COMMENT">
                        <div class="box">
                            <div class="box_1">
                                <h3>
                                    <span class="text">用户评论</span>(共
                                    <font class="f1">{{topicList.length}}</font>条评论)
                                </h3>
                                <div class="boxCenterList clearfix" style="height: 1%;">
                                    <ul class="comments">
                                        <li class="word" v-for="item in topicList" :key="item.topicid">
                                            <font class="f2">{{item.username}}</font>
                                            <font class="f3">({{item.addtime}}) </font> <br />
                                            <img :src="'themes/ecmoban_dangdang/images/stars'+ item.num + '.gif'" alt="" />
                                            <p>{{item.contents}}</p>




                                        </li>
                                    </ul>
                                    <div class="blank5"></div>
                                </div>
                            </div>
                        </div>
                        <div class="blank5"></div>
                    </div>
                </div>
                <div class="blank"></div>
            </div>
            <div id="footer">
                <div class="footer">
                    <div class="footer_nav_box">
                        <div class="footer_copyright">
                            <span> &copy; 生鲜商城 版权所有，并保留所有权利。<br /> <br />服务时间：09:00-23:00<br /> <br /> <a
                                    href="../admin/index.html" target="_blank">管理员入口</a>
                            </span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<!--此页面业务相关的脚本-->
<script type="text/javascript" src="../admin/assets/layui/layui.js"></script>
<script type="text/javascript" src="../admin/assets/js/axios.min.js"></script>
<script type="text/javascript" src="../admin/assets/js/vue.js"></script>
<script type="text/javascript" src="../admin/assets/js/jquery.min.js"></script>
<script type="text/javascript" src="./themes/index.js"></script>
<script type="text/javascript">
    const vue = new Vue({ // 实例化Vue对象
        el: '#app', // 绑定作用域
        data: { //定义数据 用于vue的双向绑定
            id: '',
            islogin: '',
            userid: '',
            realname: '',
            cate: '',
            number: '1',
            cateList: {}, // 用来保存商品类型对象数据
            hotList: {},
            goodsList: {}, // 用来保存前端显示数据
            page: {},
            count: 0,
            page: 1,
            limit: 12,
            goods: [],
            topicList: {},
        },
        methods: {
            getUrlParam: function () {
                var name, value;
                var str = location.href; // 取得整个地址栏
                var num = str.indexOf("?"); // 定位参数起始位置
                str = str.substr(num + 1); // 取得所有参数 
                var arr = str.split("&"); // 各个参数放到数组里
                for (var i = 0; i < arr.length; i++) {
                    num = arr[i].indexOf("=");
                    if (num > 0) {
                        name = arr[i].substring(0, num);
                        value = arr[i].substr(num + 1);
                        this.id = value; // 确认主键参数
                    }
                }
            },
            loadPage: function () {
                let _this = this;
                _this.getUrlParam();
                
                axios.get('http://localhost:8080/vue_gxhfztjxt/index/front.action').then(result => {
                    _this.cateList = result.data.cateList;
                    _this.hotList = result.data.hotList;
                });
                _this.userid = sessionStorage.getItem('userid');
                _this.islogin = sessionStorage.getItem('userid') == null;
                _this.realname = sessionStorage.getItem('realname');
                if(_this.islogin){
                    axios.get('http://localhost:8080/vue_gxhfztjxt/index/detail.action?id=' + _this.id).then(
                    result => {
                        _this.goods = result.data.goods;
                        _this.topicList = result.data.topicList;
                    });
                }else{
                    axios.get('http://localhost:8080/vue_gxhfztjxt/index/userdetail.action?id=' + _this.id+'&userid='+_this.userid).then(
                    result => {
                        _this.goods = result.data.goods;
                        _this.topicList = result.data.topicList;
                    });
                }
            },
            addcart: function () {
                let _this = this;
                var data = {
                    goodsid: _this.id,
                    userid: _this.userid,
                    price: _this.goods.price,
                    num: _this.number,
                };
                axios.post('http://localhost:8080/vue_gxhfztjxt/index/addcart.action', data).then(
                result => {
                    if (result.data.code > 0) {
                        window.location.href = "cart.html";
                    } else {
                        alert(result.data.message);
                    }
                });
            },
            addfav: function () {
                let _this = this;
                var data = {
                    goodsid: _this.id,
                    userid: _this.userid,
                };
                axios.post('http://localhost:8080/vue_gxhfztjxt/index/addfav.action', data).then(result => {
                    if (result.data.code > 0) {
                        window.location.href = "myfav.html";
                    } else {
                        alert(result.data.message);
                    }
                });
            }
        },
        created() { // 生命周期相关的函数
            this.loadPage();
        },
    })
</script>

</html>